home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / Navigation Services SDK / Examples / Sampler / Sampler ƒ / Common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-16  |  8.6 KB  |  344 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Common.h
  3.  
  4.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef __TYPES__
  9. #include <Types.h>
  10. #endif
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __LOWMEM__
  17. #include <LowMem.h>
  18. #endif
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __PRINTING__
  25. #include <Printing.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32. #ifndef __QDOFFSCREEN__
  33. #include <QDOffscreen.h>
  34. #endif
  35.  
  36. #ifndef __NAVIGATION__
  37. #include "Navigation.h"
  38. #endif
  39.  
  40. #ifndef Common_Defs
  41. #define Common_Defs
  42.  
  43. #define kStr255Len            255        // this length is for NewPtr call, used before making a Toolbox call
  44. #define kNameLen            32        // file name length
  45.  
  46. enum checkboxstate { dechecked,checked };
  47.  
  48. #define kStrangeErr            -1
  49.  
  50. #define kActive                0
  51. #define kInactive            255
  52.  
  53. // ASCII key characters
  54. #define kCrChar                    13        // carriage return key 
  55. #define kDelChar                8        // delete key 
  56. #define kEnterChar                3        // enter char 
  57. #define kPeriodChar                46        // period char 
  58. #define kTabKey                    9        // tab char 
  59. #define kYKey                    121
  60. #define kNKey                    110
  61. #define kEscKey                    27
  62. #define kColon                    58
  63. #define kZero                    48
  64. #define kNine                    57
  65.  
  66. #define    dOK                        1
  67. #define dCancel                    2
  68.  
  69. #define kDelayTick                10        // ticks for button hiliting
  70. #define kWindowWidth            500        // width size for the text window
  71.  
  72. #define    kMaxDocumentCount        100        // maximum number of documents allowed
  73.  
  74. #define    InitialH                16
  75. #define    InitialV                42
  76.  
  77. #define    TopMargin                6
  78. #define    LeftMargin                6
  79. #define    RightMargin                6
  80. #define    BottomMargin            6
  81.  
  82. #define    ScrollResolution        12
  83.  
  84. #define kOpenRsrcID                300
  85. #define kOpenRsrcID2            301
  86.  
  87. // file constants
  88. #define    kFileCreator            'CPAP'
  89. #define    kFileType                'TEXT'
  90. #define kFileTypePICT            'PICT'
  91. #define kOpenRsrcType            'open'
  92.  
  93. // resource constants
  94. #define rIconSuite                128
  95.  
  96. #define iIconSuite                3
  97.  
  98. // alert resources constants:
  99. #define rSaveChangesID            128
  100. #define rRevertID                129
  101. #define rGenericAlertID            130
  102. #define rAboutID                131
  103.  
  104. // resource string constants
  105. #define    rAppStringsID            128
  106. enum {
  107.     sApplicationName = 1,
  108.     sTranslationLockedErr,
  109.     sTranslationErr,
  110.     sOpeningErr,
  111.     sReadErr,                // 5
  112.     sWriteToBusyFileErr,
  113.     sBusyOpen,
  114.     sChooseFile,
  115.     sChooseFolder,
  116.     sChooseVolume,            // 10
  117.     sCreateFolder,
  118.     sChooseObject,
  119.     sSaveCopyMessage,
  120.     slSavePromptIndex,
  121.     slClosingIndex,            // 15
  122.     slQuittingIndex,
  123.     sAddRemoveTitle,
  124.     sLowMemoryErr
  125. };
  126.  
  127. #define    MenuStringsID            129
  128. enum {
  129.     slCantUndo = 1,
  130.     slUndoDrag,
  131.     slRedoDrag
  132. };
  133.  
  134. // menu resource constants
  135. #define    MenuBarID                128
  136.  
  137. #define    idAppleMenu                128
  138. #define    AboutItem                1
  139.  
  140. #define    idFileMenu                129
  141. #define    NewItem                    1
  142. #define    OpenItem                2
  143. #define    CloseItem                4
  144. #define    SaveItem                5
  145. #define SaveACopyItem            6
  146. #define    RevertItem                7
  147. //=
  148. #define DictionaryItem            9
  149. //=
  150. #define    PageSetupItem            11
  151. #define    PrintItem                12
  152. //=
  153. #define    QuitItem                14
  154.  
  155. #define    idEditMenu                130
  156. #define    iUndo                    1
  157. #define    iCut                    3
  158. #define    iCopy                    4
  159. #define    iPaste                    5
  160. #define    iClear                    6
  161. #define    iSelectAll                7
  162.  
  163. #define idUtilsMenu                131
  164. #define iSelectDir                1
  165. #define iSelectVol                2
  166. #define iSelectObject            3
  167. #define iCreateFolder            5
  168. #define iCustomOpen                7
  169. #define iAddFiles                8
  170.  
  171. #define kScrollBarWidth         16
  172. #define kScrollBarPos             kScrollBarWidth-1
  173.  
  174. // main document:
  175. typedef struct Document
  176. {
  177.     WindowPtr        theWindow;
  178.     TEHandle        theTE;
  179.     short            docTop;
  180.     RgnHandle        hiliteRgn;
  181.     
  182.     ControlHandle    vScroll;
  183.     ControlHandle    hScroll;
  184.     short            vScrollPos;
  185.     
  186.     short            fRefNum;
  187.     short            dirty;
  188.     
  189.     Handle            undoDragText;
  190.     short            undoSelStart;
  191.     short            undoSelEnd;
  192.     
  193.     short            lastSelStart;
  194.     short            lastSelEnd;
  195.  
  196.     ParamBlockRec    fioParamBlock;            // param block for file I/O operations
  197.     Handle            fPict;
  198.     Handle            fHeader;
  199.     long            fPictLength;
  200.  
  201. } Document;
  202.  
  203.  
  204. // offscreen drawing:
  205. typedef struct WindowOffscreen
  206. {
  207.     CGrafPtr        windowPort;
  208.     GDHandle        windowDevice;
  209.     GWorldPtr        offscreenWorld;
  210. } WindowOffscreen;
  211.  
  212. WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
  213.  
  214.  
  215. #define mBarHeight    (short *)0x0BAA        // Low mem global for menu bar
  216. #define EventQueue  (QHdrPtr)0x14A         // Event queue header (10 bytes)
  217. #define Mouse        ((Point*)0x830)        // processed mouse
  218. #define KeyTime     (long*)0x186        // tickcount when KEYLAST was rec'd 
  219.  
  220. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  221. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  222.  
  223. #define RectWidth(aRect) ((aRect).right - (aRect).left)
  224. #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
  225.  
  226. #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
  227. #define Min(X, Y) (  ((X)>(Y)) ? (Y) : (X) )
  228.  
  229. #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
  230.  
  231. #define kOpenPrefKey            1
  232. #define kSavePrefKey            2
  233. #define kSelectFilePrefKey        3
  234. #define kSelectFolderPrefKey    4
  235. #define kSelectVolumePrefKey    5
  236. #define kNewFolderPrefKey        6
  237. #define kSelectObjectPrefKey    7
  238.         
  239. //**************************************************************
  240.  
  241. // utility routines for detecting keydowns
  242. Boolean ModifierDown(short modifier);
  243. Boolean OptionDown(void);
  244. Boolean ShiftDown(void);
  245. Boolean CommandDown(void);
  246. Boolean ControlDown(void);
  247.  
  248. static SInt16 rnd(SInt16 max);
  249. short RandTween(short low, short high);
  250.  
  251. // file utilities:
  252. OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
  253. Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
  254. pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
  255.  
  256. // dialog control utilities
  257. void hiliteTheButton(DialogPtr theDialog, short whichItem);
  258. void AdornButton(DialogPtr theDialog, short whichItem);
  259. unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  260. void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  261. void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
  262. void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
  263.  
  264. // string utilities
  265. OSType Str2OSType(Str255 theStr);
  266. long MyStrLen(char* s);
  267. long myStringToLong(char* s);
  268. short myStringToShort(char* s);
  269. void myStrCpy(char* dst, char* src);
  270. void myStrCat(char* dst, char* src);
  271. unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
  272. char* MyP2CCopy(unsigned char* psrc,char* ctarget);
  273. unsigned char* MyC2PStr(char* theStr);
  274. char* MyP2CStr(unsigned char* theStr);
  275.  
  276. void DrawIconSuite(short resID, Rect destRect);
  277. void DebugCStr(char* msg);
  278. void AdjustCursor(Point theLoc, RgnHandle theRgn);
  279.  
  280.  
  281. // *******************************************************************
  282.  
  283. // prototypes for 'document.c'
  284. Document* NewDocument(Boolean newAsPICT);
  285. Document* IsDocumentWindow(WindowPtr theWindow);
  286. void DoUndoDrag(void);
  287. pascal void DocumentClickLoop(void);
  288. void DoActivateDocument(Document* theDocument, short activate);
  289. void DoSelectAllDocument(Document* theDocument);
  290. void UpdateWindow(Document* theDocument);
  291. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
  292. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
  293. pascal void ScrollProc(ControlHandle theControl, short theCode);
  294. void DocumentHighlightProc(void);
  295. void SizeDocWindow(Document* theDocument);
  296.  
  297. // prototypes for 'files.c'
  298. short DoSaveDocument(Document* theDocument);
  299. void DoNewDocument(Boolean newDocAsPICT);
  300. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
  301.  
  302. OSErr DoOpenDocument(void);
  303. OSErr DoOpenDocumentTheOldWay(void);
  304.  
  305. OSErr SaveACopyDocument(Document* theDocument);
  306. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  307.  
  308. void DoRevertDocument(Document* theDocument);
  309. void DoRevertDocumentTheOldWay(Document* theDocument);
  310.  
  311. // prototypes for 'Utilities.c'
  312. short TEIsFrontOfLine(short offset, TEHandle theTE);
  313. short TEGetLine(short offset, TEHandle theTE);
  314. short myTECut(TEHandle theTE);
  315. short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
  316.  
  317. // prototypes for 'Offscreen.c'
  318. void DrawOnscreen(WindowOffscreen* theOffscreen);
  319.  
  320. // prototypes for 'document.c'
  321. void AdjustDocumentView(Document* theDocument);
  322. void AdjustScrollBar(Document* theDocument);
  323. void CloseDocument(Document* theDocument, Boolean quitting);
  324. void DisableUndoDrag(void);
  325. void AddText(Document* theDocument, Ptr text, long len);
  326.  
  327. // prototypes for 'drag.c'
  328. short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
  329.  
  330. // prototypes for 'menu.c'
  331. void AdjustMenus(void);
  332. void DoMenuCommand(long select);
  333.  
  334. // prototypes for 'event.c'
  335. void EventLoop(void);
  336. pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  337. pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  338. pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  339.  
  340. OSErr AEGetDescData(const AEDesc* desc, DescType* typeCode, void* dataBuffer, ByteCount maximumSize, ByteCount* actualSize);
  341.  
  342. void DoLowMemAlert( void );
  343.  
  344. #endif // Common_Defs